home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / forth / amiga / amigaker.arc / 16.defining < prev    next >
Encoding:
Text File  |  1987-12-30  |  13.7 KB  |  362 lines

  1. ;
  2. ;  16.defining
  3. ;
  4. ;
  5.  
  6.  
  7. * ,view           (s -- ) View fields are not used, can be used to count
  8. ; word useage.
  9.                   dc.w     -1
  10.                   dc.l     link0
  11. link0             set      *-4
  12.                   dc.b     $85,$2c,'vie',$80!'w'
  13.                   cnop     0,2
  14. _comma_view       dc.l     nest
  15.                   dc.l     _0,_w_comma,_exit
  16.  
  17.  
  18.  
  19. * "create         (s str -- ) Creates a header using the string str.
  20. ; Makes a view field (1 word), next sets a 0 link field, stores name address
  21. ; into 'last', issues a duplicate message, if warning and duplicate.
  22. ; Links into the proper list (hash), sets high bits on first and last char
  23. ; of the name. Sets code field to docreate, same as a variable.
  24.                   dc.w     -1
  25.                   dc.l     link2
  26. link2             set      *-4
  27.                   dc.b     $87,'"creat',$80!'e'
  28.                   cnop     0,2
  29. _quote_create     dc.l     nest
  30.                   dc.l     _count,_here,_even
  31.                   dc.l     _2_plus,_4_plus,_place
  32.                   dc.l     _align,_comma_view,_here,_0,_comma
  33.                   dc.l     _here,_last,_store,_here
  34.                   dc.l     _warning,_fetch,_question_branch,2$
  35.                   dc.l     _find,_question_branch,1$
  36.                   dc.l     _here,_count,_type,_nest_dot_quote
  37.                   dc.b     15,' isn',$27,'t unique ',0
  38.                   cnop     0,2
  39. 1$                dc.l     _drop,_here
  40. 2$                dc.l     _current,_fetch,_hash,_dup,_fetch
  41.                   dc.l     _here,_4_minus,_rot,_store,_swap,_store
  42.                   dc.l     _here,_dup,_c_fetch,_width,_fetch,_min
  43.                   dc.l     _2dup,_plus,_minus_rot
  44.                   dc.l     _1_plus,_allot,_align
  45.                   dc.l     _nest_lit,128,_swap,_cset
  46.                   dc.l     _nest_lit,128,_swap,_cset
  47.                   dc.l     _compile,docreate,_exit
  48.  
  49. * create          (s -- ) <word>
  50. ; Creates a header with the name <word>
  51.                   dc.w     -1
  52.                   dc.l     link3
  53. link3             set      *-4
  54.                   dc.b     $86,'creat',$80!'e'
  55.                   cnop     0,2
  56. _create           dc.l     nest
  57.                   dc.l     _bl,_word,_question_uppercase
  58.                   dc.l     _quote_create,_exit
  59.  
  60. * !csp            (s -- ) save current stack level for checking.
  61.                   dc.w     -1
  62.                   dc.l     link1
  63. link1             set      *-4
  64.                   dc.b     $84,'!cs',$80!'p'
  65.                   cnop     0,2
  66. _store_csp        dc.l     nest
  67.                   dc.l     _sp_fetch,_csp,_store,_exit
  68.  
  69. * ?csp            (s -- ) Issue error message if stack has changed.
  70.                   dc.w     -1
  71.                   dc.l     link3
  72. link3             set      *-4
  73.                   dc.b     $84,'?cs',$80!'p'
  74.                   cnop     0,2
  75. _question_csp     dc.l     nest
  76.                   dc.l     _sp_fetch,_csp,_fetch,_not_equals
  77.                   dc.l     _nest_abort_quote
  78.                   dc.b     14,'Stack Changed',0
  79.                   cnop     0,2
  80.                   dc.l     _exit
  81.  
  82. * hide            (s -- ) Remove last header from the linked list.
  83.                   dc.w     -1
  84.                   dc.l     link0
  85. link0             set      *-4
  86.                   dc.b     $84,'hid',$80!'e'
  87.                   cnop     0,2
  88. _hide             dc.l     nest
  89.                   dc.l     _last,_fetch,_dup,_n_to_link,_fetch
  90.                   dc.l     _swap,_current,_fetch,_hash,_store
  91.                   dc.l     _exit
  92.  
  93. * reveal          (s -- ) Replace the last definition into the linked list.
  94.                   dc.w     -1
  95.                   dc.l     link2
  96. link2             set      *-4
  97.                   dc.b     $86,'revea',$80!'l'
  98.                   cnop     0,2
  99. _reveal           dc.l     nest
  100.                   dc.l     _last,_fetch,_dup,_n_to_link
  101.                   dc.l     _swap,_current,_fetch,_hash,_store
  102.                   dc.l     _exit
  103.  
  104. * (;uses)         (s -- ) Sets the code field of the last definition to
  105. ; the cell following.
  106.                   dc.w     -1
  107.                   dc.l     link0
  108. link0             set      *-4
  109.                   dc.b     $87,'(;uses',$80!')'
  110.                   cnop     0,2
  111. _nest_semi_colon_uses
  112.                   dc.l     nest
  113.                   dc.l     _r_from,_fetch,_last,_fetch
  114.                   dc.l     _name_from,_store,_exit
  115.  
  116. * assembler       (s -- ) Vocabulary assembler. No words are defined here
  117. ; when loading the assembler, all the words are defined.
  118.                   dc.w     -1
  119.                   dc.l     link1
  120. link1             set      *-4
  121.                   dc.b     $89,'assemble',$80!'r'
  122.                   cnop     0,2
  123. _assembler        dc.l     vocabulary_does
  124.                   dc.l     0
  125.                   dc.l     0
  126.                   dc.l     0
  127.                   dc.l     0
  128.                   dc.l     voc_link
  129. voc_link          set      *-4
  130.  
  131. * ;uses           (s -- ) Sets the code field of the last word to the
  132. ; following cell.
  133.                   dc.w     -1
  134.                   dc.l     link3
  135. link3             set      *-4
  136.                   dc.b     $85!immediate,';use',$80!'s'
  137.                   cnop     0,2
  138. _semi_colon_uses  dc.l     nest
  139.                   dc.l     _question_csp,_compile,_nest_semi_colon_uses
  140.                   dc.l     _left_bracket,_reveal,_assembler
  141.                   dc.l     _exit
  142.  
  143. * (;code)         (s -- ) Sets the code field of the last word to the
  144. ; address following.
  145.                   dc.w     -1
  146.                   dc.l     link0
  147. link0             set      *-4
  148.                   dc.b     $87,'(;code',$80!')'
  149.                   cnop     0,2
  150. _nest_semi_colon_code
  151.                   dc.l     nest
  152.                   dc.l     _r_from,_last,_fetch,_name_from
  153.                   dc.l     _store,_exit
  154.  
  155. * ;code           (s -- ) Redefines the runtime portion of the last word
  156. ; to the code following.
  157.                   dc.w     -1
  158.                   dc.l     link3
  159. link3             set      *-4
  160.                   dc.b     $85!immediate,';cod',$80!'e'
  161.                   cnop     0,2
  162. _semi_colon_code  dc.l     nest
  163.                   dc.l     _question_csp,_compile
  164.                   dc.l     _nest_semi_colon_code
  165.                   dc.l     _left_bracket,_reveal
  166.                   dc.l     _assembler,_exit
  167.  
  168. * does>           (s -- ) Specifies the run time portion of a defining
  169. ; word in high level Forth. When run the address of the created word will
  170. ; be on the stack.
  171.                   dc.w     -1
  172.                   dc.l     link0
  173. link0             set      *-4
  174.                   dc.b     $85!immediate,'does',$80!'>'
  175.                   cnop     0,2
  176. _does_from        dc.l     nest
  177.                   dc.l     _compile,_nest_semi_colon_code
  178.                   dc.l     _nest_lit,$4EB9,_w_comma
  179.                   dc.l     _nest_lit,dodoes,_comma
  180.                   dc.l     _exit
  181.  
  182. * [               (s -- ) Start interpreting, stop compiling.
  183.                   dc.w     -1
  184.                   dc.l     link3
  185. link3             set      *-4
  186.                   dc.b     $81!immediate,$80!'['
  187.                   cnop     0,2
  188. _left_bracket     dc.l     nest
  189.                   dc.l     _state,_off,_exit
  190.  
  191. * ]               (s -- ) The compiling loop. Sets 'state', looks up the
  192. ; word in the input stream, executes it if it is immediate, otherwise
  193. ; compiles it. If the word is not found, converts it to a number single or
  194. ; double. Stops when the input is empty or the state has been altered.
  195.                   dc.w     -1
  196.                   dc.l     link1
  197. link1             set      *-4
  198.                   dc.b     $81,$80!']'
  199.                   cnop     0,2
  200. _right_bracket    dc.l     nest
  201.                   dc.l     _state,_on
  202. 1$                dc.l     _question_stack,_defined,_dup
  203.                   dc.l     _question_branch,4$
  204.                   dc.l       _0_greater,_question_branch,2$
  205.                   dc.l         _execute,_branch,3$
  206. 2$                dc.l         _comma
  207. 3$                dc.l       _branch,6$
  208. 4$                dc.l     _drop,_number,_double_question
  209.                   dc.l       _question_branch,5$
  210.                   dc.l         _dliteral,_branch,6$
  211. 5$                dc.l         _drop,_literal
  212. 6$                dc.l     _true,_done_question,_question_branch,1$
  213.                   dc.l     _exit
  214.  
  215. * :               (s -- ) Starts a colon definition. The word is hidden
  216. ; until it is defined, or if recursion is required.
  217.                   dc.w     -1
  218.                   dc.l     link2
  219. link2             set      *-4
  220.                   dc.b     $81,$80!':'
  221.                   cnop     0,2
  222. _colon            dc.l     nest
  223.                   dc.l     _store_csp,_current,_fetch
  224.                   dc.l     _context,_store,_create,_hide
  225.                   dc.l     _right_bracket,_nest_semi_colon_uses
  226.                   dc.l     nest
  227.  
  228. * ;               (s -- ) Ends a colon definition. Stops compiling.
  229.                   dc.w     0
  230.                   dc.l     link3
  231. link3             set      *-4
  232.                   dc.b     $81!immediate,$80!';'
  233.                   cnop     0,2
  234. _semi_colon       dc.l     nest
  235.                   dc.l     _question_csp,_compile,_unnest
  236.                   dc.l     _reveal,_left_bracket
  237.                   dc.l     _exit
  238.  
  239. * recursive       (s -- ) Be very carefull, stack can be too small.
  240.                   dc.w     -1
  241.                   dc.l     link2
  242. link2             set      *-4
  243.                   dc.b     $89!immediate,'recursiv',$80!'e'
  244.                   cnop     0,2
  245. _recursive        dc.l     nest
  246.                   dc.l     _reveal,_exit
  247.  
  248. * constant        (s n -- ) Defines a constant.
  249. ;                 (s -- n ) Runtime returns a number.
  250.                   dc.w     -1
  251.                   dc.l     link3
  252. link3             set      *-4
  253.                   dc.b     $88,'constan',$80!'t'
  254.                   cnop     0,2
  255. _constant         dc.l     nest
  256.                   dc.l     _create,_comma,_nest_semi_colon_uses
  257.                   dc.l     doconstant
  258.  
  259. * variable        (s -- ) Defining word for variables.
  260. ;                 (s -- addr ) Runtime returns the address of the var.
  261.                   dc.w     -1
  262.                   dc.l     link2
  263. link2             set      *-4
  264.                   dc.b     $88,'variabl',$80!'e'
  265.                   cnop     0,2
  266. _variable         dc.l     nest
  267.                   dc.l     _create,_0,_comma,_nest_semi_colon_uses
  268.                   dc.l     docreate
  269.  
  270. * defer           (s -- )  Defines an execution vector, defaults to crash.
  271. ; Vectors are changed using 'is'
  272.                   dc.w     -1
  273.                   dc.l     link0
  274. link0             set      *-4
  275.                   dc.b     $85,'defe',$80!'r'
  276.                   cnop     0,2
  277. _defer            dc.l     nest
  278.                   dc.l     _create,_nest_lit,_crash
  279.                   dc.l     _comma,_nest_semi_colon_uses
  280.                   dc.l     dodefer
  281.  
  282. * vocabulary      (s -- ) Defining word for vocabularies.
  283. ; At runtime context is changed to point to the vocabulary.
  284. ; voc-link is used to forget defined vocabularies in order.
  285.                   dc.w     -1
  286.                   dc.l     link2
  287. link2             set      *-4
  288.                   dc.b     $8A,'vocabular',$80!'y'
  289.                   cnop     0,2
  290. _vocabulary       dc.l     nest
  291.                   dc.l     _create,_number_threads,_0
  292.                   dc.l     _nest_do,2$
  293. 1$                dc.l     _0,_comma
  294.                   dc.l     _nest_loop,1$
  295. 2$                dc.l     _here,_voc_link,_fetch,_comma
  296.                   dc.l     _voc_link,_store
  297.                   dc.l     _nest_semi_colon_code
  298. vocabulary_does   dc.w     $4EB9
  299.                   dc.l     dodoes
  300.                   dc.l     _context,_store,_exit
  301.  
  302. * librarybase     A word, which provides storage for the librarybase and
  303. ; links itself into the linked list lib-link.
  304.                   dc.w     -1
  305.                   dc.l     link0
  306. link0             set      *-4
  307.                   dc.b     $8B,'librarybas',$80!'e'
  308.                   cnop     0,2
  309. _librarybase      dc.l     nest
  310.                   dc.l     _create,_0,_comma,_here,_lib_link,_fetch,_comma
  311.                   dc.l     _lib_link,_store,_exit
  312.  
  313. * definitions     (s -- )  Definitions will be placed in the same vocabulary
  314. ; as the top of context.
  315.                   dc.w     -1
  316.                   dc.l     link0
  317. link0             set      *-4
  318.                   dc.b     $8b,'definition',$80!'s'
  319.                   cnop     0,2
  320. _definitions      dc.l     nest
  321.                   dc.l     _context,_fetch,_current,_store
  322.                   dc.l     _exit
  323.  
  324. * avoc            (s -- addr ) A variable used when switching to assembler,
  325. ; to hold the present context. Set back by end-code, see assembler.
  326.                   dc.w     -1
  327.                   dc.l     link1
  328. link1             set      *-4
  329.                   dc.b     $84,'avo',$80!'c'
  330.                   cnop     0,2
  331. _avoc             dc.l     docreate,0
  332.  
  333. * (is)            (s cfa -- ) the runtime for is, sets the deferred word
  334. ; following to the address on the stack.
  335.                   dc.w     -1
  336.                   dc.l     link0
  337. link0             set      *-4
  338.                   dc.b     $84,'(is',$80!')'
  339.                   cnop     0,2
  340. _nest_is          dc.l     nest
  341.                   dc.l     _r_fetch,_fetch,_to_body,_store,_r_from
  342.                   dc.l     _4_plus,_to_r
  343.                   dc.l     _exit
  344.  
  345. * is              (s cfa -- ) <word>
  346. ; Sets the deferred <word> to the address on the stack.
  347. ; Note that this system doesn't have a multitasking section as in other
  348. ; F83's. It is left up to the Amiga. Is is fairly simple, as compared to
  349. ; is in F83.
  350.                   dc.w     -1
  351.                   dc.l     link1
  352. link1             set      *-4
  353.                   dc.b     $82!immediate,'i',$80!'s'
  354.                   cnop     0,2
  355. _is               dc.l     nest
  356.                   dc.l     _state,_fetch,_question_branch,1$
  357.                   dc.l     _compile,_nest_is,_branch,2$
  358. 1$                dc.l     _tick,_to_body,_store
  359. 2$                dc.l     _exit
  360.  
  361.  
  362.